import os
from lxml import etree
import requests
import json
import time

# from article_list import article_list

url = 'https://blog.csdn.net/weixin_46192679'
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240"
r = requests.request('GET', url, headers={'User-agent': ua})
content = r.text
html = etree.HTML(content)
title_url = html.xpath('//*[@class="article-item-box csdn-tracking-statistics"]/h4/a/@href')


def TitleUrl():
    list1 = []
    for i in title_url:
        list1.append(i)
    return list1


# title_url = article_list.TitleUrl()
num = 0
while num != -1:
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    url = 'https://ip.jiangxianli.com/api/proxy_ips?page=1&country=%E4%B8%AD%E5%9B%BD'
    url = requests.get(url, headers=headers)
    versioninfo = url.text
    versioninfoPython = json.loads(versioninfo)
    arr = versioninfoPython['data']['data']
    if url.status_code == 200:
        list = 0
        for i in arr:
            url = TitleUrl()
            port = versioninfoPython['data']['data'][list]['port']
            ip = versioninfoPython['data']['data'][list]['ip']
            proxy = 'http://%s:%s' % (ip, port)
            list1 = dict({'http': proxy})
            list += 1
            for get in url:
                num += 1
                print(get)
                file = '第%s次完成' % num
                fo = open('conf.txt', 'w')
                fo.write(file + "\n")
                fo.close()
                print(list1)
                requests.get(get, proxies=list1)
                time.sleep(1)
    else:
        print('error:%s' % url.text)
